<?php
/**
 * 
 * 友情链接数据提供器
 * @author LeoNing
 *
 */
class LinksDataProvider implements IDataProvider {
	/**
	 * icon 有图片
	 * type 链接类型
	 * start 分页
	 * limit 读取数量
	 * 
	 * @see IDataProvider::provide()
	 */
	public function provide($params) {
		extract ( $params );
		$where = array ('display' => 1 );
		if (isset ( $icon )) {
			$where ['icon <>'] = '';
		}
		if (isset ( $type )) {
			$where ['type IN'] = explode ( ',', $type );
		}
		$start = isset ( $start ) ? intval ( $start ) : 1;
		$limit = isset ( $limit ) ? intval ( $limit ) : 0;
		$lM = new WebLinkModel ();
		
		$lM->sortAsc ( 'sort' )->where ( $where );
		if (isset ( $paging ) && $paging) {
			$lM->count ( true );
		}
		if ($limit > 0) {
			$lM->limit ( $limit, $start - 1 );
		}
		$links = $lM->retrieve ();
		if ($links) {
			return new CtsDataSet ( $links, $links->countTotal, $limit );
		} else {
			return new CtsDataSet ( array (), 0, $limit );
		}
	}
}